﻿using System;
using System.Collections.Generic;
using Besture.Common.Definition;
using DevExpress.Utils;
using DevExpress.Web.ASPxGridView;

namespace Besture.UI.ClassHelper
{
    public class AspxGridViewHelper
    {
        /// <summary>
        /// 初始化ASPXGridView控件
        /// </summary>
        public static void InitBaseAspxGridView(ASPxGridView gridView)
        {
            gridView.SettingsLoadingPanel.Text = "正在加载中...";
            gridView.Images.SpriteCssFilePath = "/Admin/Themes/DevTheme/DevExV3/{0}/sprite.css";
            gridView.Images.LoadingPanelOnStatusBar.Url = "/Admin/Themes/DevTheme/DevExV3/GridView/gvLoadingOnStatusBar.gif";
            gridView.Images.LoadingPanel.Url = "/Admin/Themes/DevTheme/DevExV3/GridView/Loading.gif";
            gridView.Styles.CssFilePath = "/Admin/Themes/DevTheme/DevExV3/{0}/styles.css";
            gridView.Styles.CssPostfix = "DevExV3";
            gridView.Styles.Header.ImageSpacing = 5;
            gridView.Styles.Header.SortingImageSpacing = 5;
            gridView.StylesEditors.CalendarHeader.Spacing = 1;
            gridView.StylesEditors.ProgressBar.Height = 25;
            gridView.SettingsEditing.PopupEditFormAllowResize = true;
            //隔行换色
            gridView.Styles.AlternatingRow.Enabled = DefaultBoolean.True;
            //删除提示
            gridView.SettingsBehavior.ColumnResizeMode = ColumnResizeMode.NextColumn;
            //不显示加载图片
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsPager.PageSize = string.IsNullOrEmpty(AppSettings.GetAdminPageSize()) ? 10 : int.Parse(AppSettings.GetAdminPageSize());
        }
        /// <summary>
        /// 初始化GridView控件
        /// </summary>
        public static void InitAspxGridView(ASPxGridView gridView)
        {
            /*gridView.SettingsLoadingPanel.Text = "正在加载中...";
            gridView.Images.SpriteCssFilePath = "/Admin/Themes/DevTheme/DevExV3/{0}/sprite.css";
            gridView.Images.LoadingPanelOnStatusBar.Url = "/Admin/Themes/DevTheme/DevExV3/GridView/gvLoadingOnStatusBar.gif";
            gridView.Images.LoadingPanel.Url = "/Admin/Themes/DevTheme/DevExV3/GridView/Loading.gif";
            gridView.Styles.CssFilePath = "/Admin/Themes/DevTheme/DevExV3/{0}/styles.css";
            gridView.Styles.CssPostfix = "DevExV3";
            gridView.Styles.Header.ImageSpacing = 5;
            gridView.Styles.Header.SortingImageSpacing = 5;
            gridView.StylesEditors.CalendarHeader.Spacing = 1;
            gridView.StylesEditors.ProgressBar.Height = 25;
            gridView.SettingsEditing.PopupEditFormAllowResize = true;
            //gridView.Settings.ShowGroupPanel = true;
            //gridView.SettingsText.GroupPanel = "请将列名拖动至此进行分组";
            //底部空白
            gridView.Settings.ShowFooter = true;
            //条件搜索
            gridView.Settings.ShowFilterRow = true;
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsBehavior.ConfirmDelete = true;
            gridView.SettingsText.ConfirmDelete = "该操作无法恢复，您确认执行删除吗？";
            //隔行换色
            gridView.Styles.AlternatingRow.Enabled = DefaultBoolean.True;
            //删除提示
            gridView.SettingsBehavior.ColumnResizeMode = ColumnResizeMode.NextColumn;
            gridView.Settings.ShowHeaderFilterButton = true;
            gridView.Settings.EnableFilterControlPopupMenuScrolling = true;

            //gridView.Settings.ShowVerticalScrollBar = true;
            //gridView.Settings.VerticalScrollableHeight = 465;
            //gridView.Settings.ShowHorizontalScrollBar = true;
            //不显示加载图片
            gridView.SettingsPager.Summary.Text = "共有{2}条记录，当前显示第 {0} 页";
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsPager.PageSize = 12;
            //gridView.SettingsPager.PageSize = string.IsNullOrEmpty(AppSettings.GetAdminPageSize()) ? 10 : int.Parse(AppSettings.GetAdminPageSize());*/
            gridView.SettingsLoadingPanel.Text = "正在加载中...";
            gridView.Images.SpriteCssFilePath = "/Admin/Themes/DevTheme/DevExOABlue/{0}/sprite.css";
            gridView.Images.LoadingPanelOnStatusBar.Url = "/Admin/Themes/DevTheme/DevExOABlue/GridView/gvLoadingOnStatusBar.gif";
            gridView.Images.LoadingPanel.Url = "/Admin/Themes/DevTheme/DevExOABlue/GridView/Loading.gif";
            gridView.Styles.CssFilePath = "/Admin/Themes/DevTheme/DevExOABlue/{0}/styles.css";
            gridView.Styles.CssPostfix = "DevExOABlue";
            gridView.Styles.Header.ImageSpacing = 5;
            gridView.Styles.Header.SortingImageSpacing = 5;
            gridView.StylesEditors.CalendarHeader.Spacing = 1;
            gridView.StylesEditors.ProgressBar.Height = 25;
            gridView.SettingsEditing.PopupEditFormAllowResize = true;
            //gridView.Settings.ShowGroupPanel = true;
            //gridView.SettingsText.GroupPanel = "请将列名拖动至此进行分组";
            gridView.Settings.ShowFooter = true;
            gridView.Settings.ShowFilterRow = true;
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsBehavior.ConfirmDelete = true;
            gridView.SettingsText.ConfirmDelete = "该操作无法恢复，您确认执行删除吗？";
            //隔行换色
            gridView.Styles.AlternatingRow.Enabled = DefaultBoolean.True;
            //删除提示
            gridView.SettingsBehavior.ColumnResizeMode = ColumnResizeMode.NextColumn;
            gridView.Settings.ShowHeaderFilterButton = true;
            gridView.Settings.EnableFilterControlPopupMenuScrolling = true;

            //gridView.Settings.ShowVerticalScrollBar = true;
            //gridView.Settings.VerticalScrollableHeight = 465;
            //gridView.Settings.ShowHorizontalScrollBar = true;
            //不显示加载图片
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsPager.PageSize = string.IsNullOrEmpty(AppSettings.GetAdminPageSize()) ? 10 : int.Parse(AppSettings.GetAdminPageSize());
        }

        /// <summary>
        /// 初始化GridView控件
        /// </summary>
        public static void InitAspxGridViewOrder(ASPxGridView gridView)
        {
            gridView.SettingsLoadingPanel.Text = "正在加载中...";
            gridView.Images.SpriteCssFilePath = "/Admin/Themes/DevTheme/DevExV3/{0}/sprite.css";
            gridView.Images.LoadingPanelOnStatusBar.Url = "/Admin/Themes/DevTheme/DevExV3/GridView/gvLoadingOnStatusBar.gif";
            gridView.Images.LoadingPanel.Url = "/Admin/Themes/DevTheme/DevExV3/GridView/Loading.gif";
            gridView.Styles.CssFilePath = "/Admin/Themes/DevTheme/DevExV3/{0}/styles.css";
            gridView.Styles.CssPostfix = "DevExV3";
            gridView.Styles.Header.ImageSpacing = 5;
            gridView.Styles.Header.SortingImageSpacing = 5;
            gridView.StylesEditors.CalendarHeader.Spacing = 1;
            gridView.StylesEditors.ProgressBar.Height = 25;
            gridView.SettingsEditing.PopupEditFormAllowResize = true;
            gridView.Settings.ShowGroupPanel = true;
            gridView.SettingsText.GroupPanel = "请将列名拖动至此进行分组";
            gridView.Settings.ShowFooter = true;
            gridView.Settings.ShowFilterRow = true;
            gridView.Settings.ShowFilterRowMenu = true;
            gridView.SettingsEditing.Mode = GridViewEditingMode.Inline;
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsBehavior.ConfirmDelete = true;
            gridView.SettingsText.ConfirmDelete = "该操作无法恢复，您确认执行删除吗？";
            //隔行换色
            gridView.Styles.AlternatingRow.Enabled = DefaultBoolean.True;
            //删除提示
            gridView.SettingsBehavior.ColumnResizeMode = ColumnResizeMode.NextColumn;
            gridView.Settings.ShowFilterRowMenu = true;
            gridView.Settings.ShowHeaderFilterButton = true;
            gridView.Settings.EnableFilterControlPopupMenuScrolling = true;

            gridView.Settings.ShowHorizontalScrollBar = true;
            //不显示加载图片
            gridView.SettingsLoadingPanel.ShowImage = true;
            gridView.SettingsPager.PageSize = 20;
        }



        /// <summary>
        /// 获得多选框ID
        /// </summary>
        /// <returns></returns>
        public static string GetCheckID(ASPxGridView gridView)
        {
            string rValue = "";
            try
            {
                List<object> values = gridView.GetSelectedFieldValues(new[] { gridView.KeyFieldName });
                List<string> str = new List<string>(values.Count); //初始化
                for (int i = 0; i < values.Count; i++)
                {
                    str.Add(values[i].ToString());
                }
                    
                foreach (string tempStr in str)
                {
                    rValue += tempStr + ",";
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return rValue.TrimEnd(',');
        }
    }
}